<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;

class Register extends Model implements AuthenticatableContract
{
    use SoftDeletes,Authenticatable;
    protected $table='register';
    
    protected $primaryKey = 'id';

    protected $fillable = ['name', 'email', 'password','visual_password','phone','qq','last_ip','last_login_at','company_id','real_name',
        'wechat_openid','wechat_unionid','is_prohibited'];

    protected $dates = ['deleted_at'];

    //获取二级用户(对应user表)
    public function comuser()
    {
        $ru = RegUser::where('register_id',$this->id)->whereIn('status',[1,3])->first();
        if(empty($ru)){
            return null;
        }
        $user = User::find($ru->user_id);
        return $user;
    }
}